Skip to content

写入字符串到文件 - WriteStringToFile

函数简介

将字符串写入到指定文件,支持多种字符编码格式。

接口名称

WriteStringToFile

DLL调用

c
int WriteStringToFile(long instance, string filePath, string data, int encoding);

参数说明

参数名类型说明
instance长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
filePath字符串目标文件的完整路径。
data字符串要写入的字符串内容。
encoding整数型字符编码格式:0 ANSI/GBK;1 UTF-8(无BOM);2 UTF-8(带BOM);3 Unicode(UTF-16 LE);4 Unicode(UTF-16 BE)。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
ola.WriteStringToFile("logs/out.txt", "hello", false);
csharp
using OLAPlug;

var ola = new OLAPlugServer();
ola.WriteStringToFile("logs/out.txt", "hello", false);
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
ola.WriteStringToFile("logs/out.txt", "hello", false)
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
ola.WriteStringToFile("logs/out.txt", "hello", false);
cpp
var ola = com("OlaPlug.OlaSoft")
ola.WriteStringToFile("logs/out.txt", "hello", false);
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ola.WriteStringToFile("logs/out.txt", "hello", false);
text
.局部变量 ola, OLAPlug
ola.创建 ()
ola.WriteStringToFile("logs/out.txt", "hello", false)
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
ola.WriteStringToFile("logs/out.txt", "hello", false);
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
ola.WriteStringToFile("logs/out.txt", "hello", false);
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
ola.WriteStringToFile("logs/out.txt", "hello", false);

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
WriteStringToFile(instance, "logs/out.txt", "hello", false);
csharp
long instance = CreateCOLAPlugInterFace();
WriteStringToFile(instance, "logs/out.txt", "hello", false);
python
from ctypes import CDLL, c_int, c_int64, create_string_buffer

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
WriteStringToFile(instance, "logs/out.txt", "hello", false)

返回值

1 成功,0 失败。

注意事项

  • 如果文件已存在,将覆盖原有内容。
  • 如果目录不存在,写入会失败。
  • 选择正确的编码格式很重要,避免乱码。
  • 写入系统目录可能需要管理员权限。